package model;

import jAudio.org.oc.ocvolume.dsp.endPt;
import jAudio.org.oc.ocvolume.dsp.featureExtraction;

import java.io.File;
import java.io.FilenameFilter;

public class WavParser {
	
	protected static final String WAV_EXTENSION = ".wav";
	protected static final int attributesCountY = 12;
	protected static final int MISSING_VALUE = 0;
	
	protected static double[][] getCoefficients(short[] signal) {
		signal = endPt.absCut(signal);
		featureExtraction fE = new featureExtraction();
		double[][] coeffs = fE.process(signal, StdAudio.READ_SAMPLE_RATE);
		return coeffs;
	}
	
	protected static double[][] getCoefficients(String fName) {
		short[] signal = StdAudio.read(fName);
		return getCoefficients(signal);
	}

	protected static File[] getFiles(String fName, final String extension) {
		File f = new File(fName);

		if (f.isDirectory()) {
			return f.listFiles(new FilenameFilter() {
				public boolean accept(File dir, String filename) {
					return filename.endsWith(extension);
				}
			});
		} else {
			File[] result = new File[1];
			result[0] = f;
			return result;
		}
	}
}
